import {Button} from 'antd';
import {WeaRightMenu,WeaDialog } from 'ecCom';
import { WeaLocaleProvider } from 'ecCom';
import * as mobx from 'mobx'
import {Condition} from './Condition'
const getLabel = WeaLocaleProvider.getLabel;

class ModalSave extends React.Component {
	constructor(props) {
        super(props);
  }

  componentDidMount(){
    const {value,getModalForm} = this.props;
    getModalForm(value);
  }

  componentWillReceiveProps(nextProps) {
  }

  shouldComponentUpdate(nextProps, nextState) {

    return true;
  }

  componentWillUnmount() {
    //组件卸载时一般清理一些状态
  }

  //关闭模态框并清空数据
  handleCancel = () => {
      this.props.clearformRp();//清空数据
      this.props.closeModel(false);
  }

  handleSubmit = (e) => {
        const {value,formRp} = this.props;
        let fromParam = formRp.getFormParams();
        let that = this;
        let formValue = Object.assign({},{
            _guid1:value._guid1,
            tbName:fromParam.tbName,
            description:fromParam.description,
            rptTypeName:value.rptTypeName,
        });

        formRp.validateForm().then( f => {
            if(f.isValid){
              // 验证通过
              that.props.saveModelInfo(formValue);//保存
              that.handleCancel();
            } else {
              f.showErrors();
            }
        });
  }

  getBottomButton(){
    const {loading} = this.props;
    let buts=[];
    buts.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@c2vjrw@Save`} type="primary" style={{marginRight:10}} onClick={this.handleSubmit.bind(this)} disabled={loading}>{getLabel(384114,'保存')}</Button>);
    return buts;
  }
  
  getRightMenu(){
    const {loading} = this.props;
    let btns = [];
    this.handleSubmit.bind(this);
    btns.push({
            key:"addShare",
            icon: <i className='icon-coms-Preservation'/>,
            content:getLabel(384114,'保存'),
            disabled:loading,
            onClick:()=>{this.handleSubmit();}
     });
    return btns;
  }

	render(){
		const {showModal,formRp,conditionRp} = this.props;

		return(
				<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@wqp53e`}
              className = "weaver-fna-saveModal"
              icon='icon-coms-Finance'
              iconBgcolor='#f14a2d'
			        title={getLabel(82523,"将当前查询结果保存为")}
			        visible={showModal}
			        style={{width:526}}
              maskClosable={false}
              onCancel={this.handleCancel}
          		buttons={this.getBottomButton()}
              moreBtn={{datas:this.getRightMenu(),collectParams:{favname:getLabel(28111,'收藏'), favouritetype:5}}}
		    >

        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@250a29`} 
          datas={this.getRightMenu()}
          collectParams={{favname:getLabel(28111,'收藏'), favouritetype:5}}
        > 
          <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@6mb44v`}
            formRp={formRp}
            conditionRp={conditionRp}
          />
        </WeaRightMenu>
   			</WeaDialog>
		)
	}
}

export default ModalSave;